#-*-encoding:utf8-*-

import pickle


##Analysis area_ci map size**********************

def analysis_area_ci_map_size(map_area_ci_dict):
    """
    May used to define target type based on different feature dimension.
    """
    len_dict = {}
    n = 0

    for ks in map_area_ci_dict.keys():
        len_dict.setdefault(len(map_area_ci_dict[ks]),set())
        len_dict[len(map_area_ci_dict[ks])].add(ks)

    sorted_keys = len_dict.keys()
    sorted_keys.sort()
    #print sorted_keys

    for k in sorted_keys:
        print 'length:',k,':number of members:',
        print len(len_dict[k]),
        print 'i.e.:',len_dict[k]
        n += len(len_dict[k])

    print 'numbers of areas:',n
#********************************


#****************dump and load pickle*********************
def bak_dict_pickle(filename,dict_to_bak):
    
    with open(filename,'w') as f:
        pickle.dump(dict_to_bak,f)


def load_dict_pickle(filename):
    with open(filename,'r') as rf:
        _dict = pickle.load(rf)
    return _dict

